#文件路径
BASE_PATH:= .
BIN_PATH:= $(BASE_PATH)/bin
OBJ_PATH:= $(BASE_PATH)/obj
HSRC_PATH:= $(BASE_PATH)/src/net
CSRC_PATH:= $(BASE_PATH)/src/test

#参数
CC:= g++ -std=c++11 
FLAG:= -Wall -g 

#设置makefile搜索头文件路径
INCPATH:= $(BASE_PATH) $(HSRC_PATH)

#设置makefile搜索库文件路径
LIBPATH:= $(BIN_PATH) 

#设置动态链接库文件名称
LIBFILE:=boost_system boost_context boost_coroutine
#编译命令
COMPFLAG:= $(FLAG) $(addprefix -I, $(INCPATH))

#链接命令
LINKFLAG:=$(FLAG) $(addprefix -L,$(LIBPATH)) $(addprefix -l,$(LIBFILE))

#源代码文件 生成OBJ文件
HSRC= $(wildcard $(HSRC_PATH)/*.hpp)
CSRC= $(wildcard $(CSRC_PATH)/*.cpp)
#OBJ=$(patsubst %.hpp, ${OBJ_PATH}/%.o, $(notdir ${HSRC}))
OBJ=$(patsubst %.cpp, $(OBJ_PATH)/%.o, $(notdir $(CSRC)))

#编译目标文件
TARGET:= $(BIN_PATH)/testnet

#################################################
#编译命令
build: mkdir $(TARGET)
release: mkdir $(TARGET)

#链接
$(TARGET): $(OBJ)
	@echo '+++++++++++++Make echo : build $(TARGET)'
	@$(CC) $(OBJ) -o $@ $(LINKFLAG)

$(OBJ_PATH)/%.o:$(HSRC_PATH)/%.hpp
	@echo Compile file $<, `more $<|wc -l` lines ....
	@$(CC) $(COMPFLAG) -c $< -o $@

$(OBJ_PATH)/%.o:$(CSRC_PATH)/%.cpp
	@echo Compile file $<, `more $<|wc -l` lines ....
	@$(CC) $(COMPFLAG) -c $< -o $@


#######################################################
#定义MAKE 参数
.PHONY: mkdir clean

mkdir:
	@-if [ ! -e $(BIN_PATH) ]; then mkdir $(BIN_PATH); fi;
	@-if [ ! -e $(OBJ_PATH) ]; then mkdir $(OBJ_PATH); fi;

clean:
	@echo '+++++++++ Make echo: clean $(TARGET)'
	@echo $(OBJ)
	@rm -f $(BIN_PATH)/$(TARGET)
	@rm -f $(addprefix $(OBJ_PATH)/, $(OBJ))











